import axiosService from 'axios';
import { message } from 'antd';
import { hashHistory } from 'dva/router';

axiosService.interceptors.response.use(
    (response) => {
        return response;
    },
    (error) => {
        if (error && error.response) {
            switch (error.response.status) {
                case 400: error.message = '请求错误'; break;
                case 401: error.message = '此次登录已失效，请重新登陆'; break;
                case 403: error.message = '拒绝访问'; break;
                case 404: error.message = '请求出错'; break;
                case 408: error.message = '请求超时'; break;
                case 500: error.message = '服务器错误'; break;
                case 501: error.message = '服务未实现'; break;
                case 502: error.message = '网络错误'; break;
                case 503: error.message = '服务不可用'; break;
                case 504: error.message = '网络超时'; break;
                case 505: error.message = 'HTTP版本不受支持'; break;
                default: error.message = `连接出错!`;
            }
        } else {
            error.message = '连接服务器失败!'
        }
        message.warning(error.message);
        if (error.response.status == "401") {
            hashHistory.push("/login")
        }
    }
);


